import { get, post, put, del } from '@/utils/http/request'
import { R, P } from '@/utils/http/type'

export * from './types/category'
import {
  AddShopGoodsCategory,
  ShopGoodsCategory,
  ShopGoodsCategoryCascader,
  ShopGoodsCategoryTree,
  UpdateShopGoodsCategory,
} from './types/category'

/**
 * 获取分类详情
 */
export const getShopGoodsCategoryDetail = (id: number) => {
  return get<R<ShopGoodsCategory>>(`/goods/category/${id}`)
}

/**
 * 修改商品分类
 */
export const updateShopGoodsCategory = (data: UpdateShopGoodsCategory) => {
  return put<ShopGoodsCategory>('/goods/category', data)
}

/**
 * 获取分类级联
 */
export const getShopGoodsCategoryCascader = () => {
  return get<R<ShopGoodsCategoryCascader[]>>('/goods/category/cascader')
}

/**
 * 添加商品分类
 * @param data
 * @returns
 */
export const addShopGoodsCategory = (data: AddShopGoodsCategory) => {
  return post<AddShopGoodsCategory>('/goods/category', data)
}

/**
 * 删除商品分类
 */
export const deleteCategory = (id: number) => {
  return del<R<any>>(`/goods/category/${id}`)
}

/**
 *获取商品分类列表
 */
export const getShopGoodsCategoryTree = () => {
  return get<R<ShopGoodsCategoryTree[]>>('/goods/category')
}
